<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./dist//include-openlayers-local.js"></script>
    <script src="https://lib.baomitu.com/jquery/3.6.0/jquery.js"></script>
    <style>
      body {
        position: relative;
      }
      #map {
        width: 100vw;
        height: 100vh;
      }
      #on {
        position: absolute;
        width: 200px;
        height: 200px;
        right: 0px;
        bottom: 5px;
        z-index: 2000;
      }
      #en {
        position: absolute;
        width: 200px;
        height: 200px;
        right: 220px;
        bottom: 5px;
        z-index: 2000;
      }
    </style>
  </head>
  <body>
    <img id="on" src="./img/矢量.png" />
    <img id="en" src="./img/影像.png" />
    <div id="map"></div>

    <script>
      // 矢量
      var gaodeMapLayer = new ol.layer.Tile({
        title: "高德地图",
        source: new ol.source.XYZ({
          url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}",
          wrapX: false,
        }),
      })
      //   影像地图
      var image = new ol.layer.Tile({
        title: "高德地图",
        source: new ol.source.XYZ({
          url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}",
          wrapX: false,
        }),
      })

      var map = new ol.Map({
        layers: [gaodeMapLayer],
        view: new ol.View({
          center: [114, 30],
          projection: "EPSG:4326",
          zoom: 8,
          minZoom: 2,
        }),
        target: "map",
      })
      $("#on").click(function () {
        map.addLayer(gaodeMapLayer)
        map.removeLayer(image)
      })
      $("#en").click(function () {
        map.removeLayer(gaodeMapLayer)
        map.addLayer(image)
      })
    </script>
  </body>
</html>
